משתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

Size: px
Start display at page:

Download "משתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1"

Transcription

1 משתנים שעור מס. 2 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

2 תפקיד המשתנים הצהרה על משתנה השמת ערך במשתנה int a, b, c; a = 1234; b = 99; c = a + b; משתנים מאפשרים לנו לשמור מידע בתוכנית 2

3 סוגי משתנים הצהרת משתנים סוג משתנה int double boolean char String הצהרת משתנים ערכים מספרים שלמים מספרים ממשיים ערכים בוליאנים תווים סדרת תווים דוגמאות , w 2 \n A ABC 23 type variable_name_1, variable_name_2,..., variable_name_n; int a; a= 3; char c; c = 3 ; String s; a= 3; 3

4 מעקב אחרי ערכי משתנים בתוכנית a b c int a, b; לא מוגדר לא מוגדר a = 1234; לא מוגדר 1234 b = 99; int c = a; a = b; b = c;

5 int פעולת החיבור עבור Strings ו public class IntAndStrings { public static void main(string[] args) { int a = 1234; int b = 56; System.out.println(a + b); // summation of integers String sa = "1234"; String sb = "56"; System.out.println(sa + sb); // summation of Strings // automatic conversion of int to String String sc = "" + a + b; System.out.println(sc); $ java IntAndStrings פעולת החיבור מוגדרת הסכום עבור מספרים ושרשור עבור מחרוזות 5

6 מעבר ממחרוזות למספרים public class Sum { השיטות הפיכת מחרוזת למספר Integet.parseInt() Double.parseDouble() תוכנית המקבלת שני מספרים ומדפיסה את סכומם public static void main(string[] args) { int a = Integer.parseInt( args[0] ); int b = Integer.parseInt( args[1] ); System.out.println("The sum is: " + (a + b) ); $ java Sum 5 4 The sum is: 9 6

7 פעולות חשבון ב integers הערות בחילוק לא קיימת שארית שארית החילוק שגיאה קדימות ל * קדימות ל / חישוב מבוצע משמאל לימין סגנון כתיבה טוב קדימות ל )( תוצאה ביטוי * 3 5 / 3 5 % 3 1 / 0 3 * / (3 5) (5 2) טווח המספרים מטיפוס int הוא :

8 אופרטור המודולו % במספרים שלמים a % b a ( a / b) * b 17 % 3 = 17 (17/3) * * 3 8

9 פעולות חשבון ב double תוצאה e Infinity NaN ביטוי e23 / / % / 0.0 Math.sqrt(2.0) Math.sqrt(-1.0) טווח המספרים מסוג double הוא: e-324d to e+308d 9

10 אופרטור המודולו % במספרים ממשיים a % b a (int)( a/ b) * b 10.0 % = 10.0 (int)(10.0/ 3.141) * (int) * *

11 חישוב שורשי הפולינום x 2 +bx+c x 2 +bx+c public class Quadratic { תוכנית לחישוב שורשי הפולינום public static void main(string[] args) { double b = Double.parseDouble( args[0] ); double c = Double.parseDouble( args[1] ); double discriminant = b*b - 4.0*c; double d = Math.sqrt(discriminant); System.out.println( (-b + d) / 2.0); System.out.println( (-b - d) / 2.0); $ java Quadratic $ java Quadratic NaN NaN 11

12 משתנים בוליאניים משתנה יכול לקבל רק אחד משני ערכים:,! פעולות לוגיות &&,, האופרטור && AND האופרטור OR! האופרטור NOT a b a && b a b a b a!a if ( test_grade >= 60 && exercise_grade>=60 ) System.out.println ( You passes the course ); דוגמא 12

13 אופרטורים להשוואה משמעות y קטן מ x y קטן או שווה ל x y גדול מ x y גדול או שווה x y שווה ל x y שונה מ x אופרטור > >= > >= ==!= דוגמא x < y x <= y x > y x >= y x == y x!= y 13

14 תוכנית להשוואת מספרים public class IsOrdered { תוכנית הבודקת האם שלושה מספרים מסודרים בסדר עולה public static void main(string[] args) { double a = Double.parseDouble( args[0] ); double b = Double.parseDouble( args[1] ); double c = Double.parseDouble( args[2] ); boolean firsttwo = (a <= b); boolean lasttwo = (b <= c); boolean allthree = firsttwo && lasttwo; System.out.println("Are the numbers ordered? " + allthree); $ java IsOrdered Are the numbers ordered? $ java IsOrdered Are the numbers ordered? 14

15 שיטות מתמטיות עיקריות double Math.E() Value of e, double Math.PI() Value of pi, double Math.sin(ar) Returns the sine of ar. double Math.cos(ar) Returns the cosine of ar. double Math.tan(ar) Returns the tangent of ar. מספרים אקראיים קבועים מתמטיים שיטות טריגונומטריות double Math.sqrt(d) Returns the square root of d. t Math.abs(x) Returns absolute value of x with same type as the parameter: int, long, float, or double. t Math.max(x, y) Returns maximum of x and y with same type as the parameter: int, long, float, or double. t Math.min(x, y) Returns minimum of x and y with same type as the parameter: int, long, float, or double. double Math.random() Returns a number x in the range, 0.0 <= x < 1.0. מספרים אקראיים 15

16 מעבר בין סוגי משתנים double מעבר בטוח אין איבוד מידע int double בטוח לא מעבר יש איבוד מידע int 16

17 Type conversion - error public class TypeConversion { public static void main(string[] args) { double a = 3.5; int n = a; System.out.println(n); $ javac TypeConversion.java TypeConversion.java:5: possible loss of precision found : double required: int int n = a; ^ 1 error $ 17

18 Type conversion public class TypeConversion1 { public static void main(string[] args) { double a = 3.5; int n = (int) a; System.out.println(n); $ javac TypeConversion1.java dror@dror-1 ~/java $ java TypeConversion

19 סיכום מעבר בין משתנים ערך סוג String int int long int double double int int ביטוי Integer.parseInt( 123 ); (int) Math.Round(3.6758) (int) Math.Round(3.6758) 11 * 0.3 (int) 11 * * (int) 0.3 (int) (11 * 0.3) 19

מבוא לתכנות תוכנית שעור מס. 1 1 דר' דרור טובי, המרכז האוניברסיטאי אריאל בשומרון.

מבוא לתכנות תוכנית שעור מס. 1 1 דר' דרור טובי, המרכז האוניברסיטאי אריאל בשומרון. מבוא לתכנות תוכנית ראשונה שעור מס. 1 דרור טובי דר' 1 מבוא לתכנות בשפת ++C C \ שלום!! מרצה ד"ר דרור טובי, drorto@ariel.ac.il שעות קבלה: יום ב, 10-12 טלפון )אריאל( 03 9076547 אתר הקורס: http://www.ariel.ac.il/cs/pf/tdror/courses/cpp

More information

מערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

מערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 מערכים שעור מס. 4 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 למה מערכים? ברצוננו לאחסן בתוכנית ציוני בחינה כדי לחשב את ממוצע הציונים וסטיית התקן. נניח ש 30 סטודנטים לקחו

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 234127 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 2013 Based on slides of Dr. Eran Eden, Weizmann 2008 1 >>g = [89 91 80 98]; >>p

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 23427 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 203 Based on slides of Dr. Eran Eden, Weizmann 2008 ביטויים לוגיים דוגמא: תקינות

More information

תוכנה 1 טיפוסי השפה טיפוסים לא פרימיטיביים הטיפוסים הפרימיטיביים מחרוזות המרה למספרים תרגול 2: טיפוסי שפה, מחרוזות, מערכים ושגיאות

תוכנה 1 טיפוסי השפה טיפוסים לא פרימיטיביים הטיפוסים הפרימיטיביים מחרוזות המרה למספרים תרגול 2: טיפוסי שפה, מחרוזות, מערכים ושגיאות טיפוסי השפה תוכנה 1 תרגול 2: טיפוסי שפה, מחרוזות, מערכים ושגיאות טיפוסים יסודיים (פרימיטיביים): 8 טיפוסים מוגדרים בשפה שמיועדים להכיל ערכים פשוטים: מספרים שלמים: byte, short, int, long מספרים ממשיים: float,

More information

קורס תכנות שיעור שני: שימוש במשתנים,

קורס תכנות שיעור שני: שימוש במשתנים, קורס תכנות שיעור שני: שימוש במשתנים, בקרת זרימה, לולאות 1 נושאי השיעור היום משתנים )variables( טיפוסי משתנים בשפת C הגדרת משתנים השמה למשתנים פעולות על משתנים קליטת ערכים מהמשתמש הדפסה משתנים בקרת זרימה

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 234127 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 2013 Based on slides of Dr. Eran Eden, Weizmann 2008 1 motivation Proper academic

More information

מבוא למדעי המחשב תירגול 2: מבוא למדעי המחשב מ' - תירגול 2

מבוא למדעי המחשב תירגול 2: מבוא למדעי המחשב מ' - תירגול 2 מבוא למדעי המחשב תירגול 2: לולאות, קלט, וטיפוסים 1 תוכנייה לולאת while קלט טיפוסי משתנים המרת טיפוסים טיפוס char 2 לולאת while 3 לולאת while קטע קוד מתבצע שוב ושוב כל עוד תנאי מתקיים int number = 40; while(number>0)

More information

מבוא לתכנות ב- JAVA מעבדה 2

מבוא לתכנות ב- JAVA מעבדה 2 מבוא לתכנות ב- JAVA מעבדה 2 מה בתרגול טיפוסים פרימיטיביים המרות טיפוסים אופרטורים יחסיים ולוגיים משפט if-else בתרגול הקודם טיפוסים פרימיטביים לייצוג מספרים שלמים וממשיים ואופרטורים לפעולות בין מספרים.1

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 5/20/2013 9:37:22 AM Why Programming? Why programming? Need

More information

מבוא למדעי המחשב תירגול 3:

מבוא למדעי המחשב תירגול 3: מבוא למדעי המחשב תירגול 3: לולאות, קלט, וטיפוסים תוכנייה לולאת while קלט טיפוסי משתנים המרת טיפוסים טיפוס char מבוא למדעי המחשב מ' - תירגול 3 2 לולאת while מבוא למדעי המחשב מ' - תירגול 3 3 לולאת while

More information

מבוא למדעי המחשב הרצאה 2: ראשונים בשפת C

מבוא למדעי המחשב הרצאה 2: ראשונים בשפת C מבוא למדעי המחשב צעדים הרצאה 2: ראשונים בשפת C מבוסס על שקפים שנערכו ע"י שי ארצי, גיתית רוקנשטיין ז"ל, איתן אביאור, סאהר אסמיר,מיכאל אלעד, רון קימל ודן רביב. עדכון אחרון: יחיאל קמחי, אוקטובר 2014 תוכנייה

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program 1 Why Programming? Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies,

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 1/29/11 6:37 AM! Why Programming? Why programming? Need to

More information

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator מבוא למדעי המחשב 2017 תרגול 8 רשימה משורשרת כללית, Comparator בתרגול היום. LinkedList בניית ההכללה מ- LinkIntList תרגול המבנה ושימושיו ממשקים: Comparator Sorted Linked List ל- LinkedList ע"י שימוש ב- Comparator

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies, subject

More information

1.1 Your First Program! Naive ideal. Natural language instructions.

1.1 Your First Program! Naive ideal. Natural language instructions. Why Programming? Why programming? Need to tell computer what you want it to do. 1.1 Your First Program Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies, subject

More information

! Widely available. ! Widely used. ! Variety of automatic checks for mistakes in programs. ! Embraces full set of modern abstractions. Caveat.

! Widely available. ! Widely used. ! Variety of automatic checks for mistakes in programs. ! Embraces full set of modern abstractions. Caveat. Why Java? Lecture 2: Intro to Java Java features.! Widely available.! Widely used.! Variety of automatic checks for mistakes in programs.! Embraces full set of modern abstractions. Caveat.! No perfect

More information

תוכנה 1 סמסטר א' תשע"א

תוכנה 1 סמסטר א' תשעא General Tips on Programming תוכנה 1 סמסטר א' תשע"א תרגול מס' 6 מנשקים, דיאגרמות וביטים * רובי בוים ומתי שמרת Write your code modularly top-down approach Compile + test functionality on the fly Start with

More information

הנכות 1 םוכיס לוגרת 14 1

הנכות 1 םוכיס לוגרת 14 1 תוכנה 1 סיכום תרגול 14 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers

More information

Built-in data types. logical AND logical OR logical NOT &&! public static void main(string [] args)

Built-in data types. logical AND logical OR logical NOT &&! public static void main(string [] args) Built-in data types logical AND logical OR logical NOT &&! public static void main(string [] args) Fundamentals of Computer Science Keith Vertanen Copyright 2013 Variables Variables and data types Stores

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

Built-in data types. public static void main(string [] args) logical AND logical OR logical NOT &&! Fundamentals of Computer Science

Built-in data types. public static void main(string [] args) logical AND logical OR logical NOT &&! Fundamentals of Computer Science Built-in data types logical AND logical OR logical NOT &&! public static void main(string [] args) Fundamentals of Computer Science Variables Overview Allows us to store and compute on data For now we'll

More information

תרגול 4 פונקציות. מבנה של פונקציה: public static <return value type> <function name> (<arg1 type> <arg1>, <arg2 type> <arg2>, ) { <function body> }

תרגול 4 פונקציות. מבנה של פונקציה: public static <return value type> <function name> (<arg1 type> <arg1>, <arg2 type> <arg2>, ) { <function body> } נושאי התרגול: מה הן פונקציות הגדרת פונקציה,קריאה לפונקציה העברת ארגומנטים,החזרת ערך או void העברת משתנים פרימיטיביים ומערכים לפונקציה העמסה של פונקציות תרגול 4 פונקציות מוטיבציה לעיתים,אנו נזקקים לבצע

More information

תרגילים ופתרונות בשפת - C הסתעפויות

תרגילים ופתרונות בשפת - C הסתעפויות תרגילים ופתרונות בשפת - C הסתעפויות כתב וערך: שייקה בילו תרגיל - 1 כתוב תוכנית שתקבל מהמשתמש שלושה מספרים, ותציג את הגדול מביניהם על המסך. #include void main() int mis1, mis2, mis3, max; printf("please

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of N heavenly bodies, subject

More information

סכום (סדרת ערכים) אחרת - דוגמא: סכום-ספרות (num) אם < 10 num החזר 1 או אם = 0 = num החזר 0 public static int numofdigits (int num)

סכום (סדרת ערכים) אחרת - דוגמא: סכום-ספרות (num) אם < 10 num החזר 1 או אם = 0 = num החזר 0 public static int numofdigits (int num) 1 תבנית צבירה תבניות אלגוריתמיות לפעולות רקורסיביות תבנית צבירה לסדרת ערכים: סכום (סדרת ערכים) החזר את ערך הקצה + סכום (סדרת הערכים ללא ערך הקצה) דוגמא: פעולה המחזירה את סכום הספרות שבמספר שלם לא שלילי

More information

int: integers, no fractional part double: floating-point numbers (double precision) 1, -4, 0 0.5, , 4.3E24, 1E-14

int: integers, no fractional part double: floating-point numbers (double precision) 1, -4, 0 0.5, , 4.3E24, 1E-14 int: integers, no fractional part 1, -4, 0 double: floating-point numbers (double precision) 0.5, -3.11111, 4.3E24, 1E-14 A numeric computation overflows if the result falls outside the range for the number

More information

1.1 Your First Program

1.1 Your First Program Why Programming? Idealized computer. "Please simulate the motion of a system of N heavenly bodies, subject to Newton's laws of motion and gravity." 1.1 Your First Program Prepackaged software solutions.

More information

Lecture 2: Intro to Java

Lecture 2: Intro to Java Why Java? Lecture 2: Intro to Java Java features. Widely available. Widely used. Variety of automatic checks for mistakes in programs. Embraces full set of modern abstractions. 2 Why Java? Why Java? Java

More information

A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts,

A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders,

More information

1.1 Your First Program

1.1 Your First Program A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders,

More information

מבוא לתכנות ב- JAVA תרגול 7

מבוא לתכנות ב- JAVA תרגול 7 מבוא לתכנות ב- JAVA תרגול 7 רקורסיה - הקדמה הגדרה רקורסיבית: חדר הוא מסודר אם צד שמאל שלו מסודר שלו מסודר. וצד ימין שיטת פתרון רקורסיבית: פתרון מופעים פשוטים יותר של בעיה בכדי לפתור את הבעיה המקורית רקורסיה

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what to do. Please simulate the motion of N heavenly bodies, subject to Newton s laws of motion and gravity. Prepackaged software

More information

2/9/2012. Chapter Four: Fundamental Data Types. Chapter Goals

2/9/2012. Chapter Four: Fundamental Data Types. Chapter Goals Chapter Four: Fundamental Data Types Chapter Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of causes for overflow and roundoff

More information

double float char In a method: final typename variablename = expression ;

double float char In a method: final typename variablename = expression ; Chapter 4 Fundamental Data Types The Plan For Today Return Chapter 3 Assignment/Exam Corrections Chapter 4 4.4: Arithmetic Operations and Mathematical Functions 4.5: Calling Static Methods 4.6: Strings

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

Important Java terminology

Important Java terminology 1 Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. Primitive data פרימיטיביים) (נתונים include common, fundamental values as

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

DATA TYPES AND EXPRESSIONS

DATA TYPES AND EXPRESSIONS DATA TYPES AND EXPRESSIONS Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment Mathematical

More information

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 4 Fundamental Data Types Chapter Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of causes for overflow and roundoff errors

More information

מבוא לתכנות בשפת C. Tzachi (Isaac) Rosen

מבוא לתכנות בשפת C. Tzachi (Isaac) Rosen מבוא לתכנות בשפת C מצביעים והקצאה דינאמית כתובות של משתנים לכל משתנה כתובת של המקום שלו בזיכרון כבר ראינו: שם של מערך הוא למעשה הכתובת של התא הראשון )באינדקס 0( של המערך להזכירכם: תא של מערך הינו משתנה

More information

AP Computer Science A. Return values

AP Computer Science A. Return values AP Computer Science A Return values Distance between points Write a method that given x and y coordinates for two points prints the distance between them Pseudocode? Java's Math class Method name Math.abs(value)

More information

פתרון מוצע לבחינת מה"ט ב_שפת c מועד אביב תשע"ח, פברואר 8102 מחבר: מר שייקה בילו, מכללת אורט רחובות

פתרון מוצע לבחינת מהט ב_שפת c מועד אביב תשעח, פברואר 8102 מחבר: מר שייקה בילו, מכללת אורט רחובות פתרון מוצע לבחינת מה"ט ב_שפת c מועד אביב תשע"ח, פברואר 8102 מחבר: מר שייקה בילו, מכללת אורט רחובות שאלה מספר 1 התוכנית מגדירה חמישה משתנים שלמים: השלושה הראשונים הם שלושה מצביעים - *s *t,i. j ושלושה נוספים

More information

חוברת תרגילים לתרגול יסודות התכנות

חוברת תרגילים לתרגול יסודות התכנות פעולות קלט ופלט חוברת תרגילים לתרגול יסודות התכנות קלוט 3 מספרים. סכם אותם, הצג את שלושתם ואת תוצאת הסיכום. int num1, num2, num3,sum; Console.WriteLine("please enter 3 numbers"); num1 = int.parse(console.readline());

More information

1.3 Conditionals and Loops

1.3 Conditionals and Loops 1 1.3 Conditionals and Loops any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops to infinity and beyond Math primitive data types

More information

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac

More information

1/16/12. CS 112 Introduction to Programming. A Foundation for Programming. (Spring 2012) Lecture #4: Built-in Types of Data. The Computer s View

1/16/12. CS 112 Introduction to Programming. A Foundation for Programming. (Spring 2012) Lecture #4: Built-in Types of Data. The Computer s View 1/16/12 A Foundation for Programming CS 112 Introduction to Programming (Spring 2012) any program you might want to write Lecture #4: Built-in Types of Data objects Zhong Shao methods and classes graphics,

More information

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below. C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

More information

תוכנה 1. תרגול 1: סביבת העבודה ומבוא ל- Java

תוכנה 1. תרגול 1: סביבת העבודה ומבוא ל- Java תוכנה 1 תרגול 1: סביבת העבודה ומבוא ל- Java 1 מנהלות אתר הקורס: http://courses.cs.tau.ac.il/software1/1718b/ מתרגלים: ברית יונגמן )שעת קבלה: רביעי ב- 9:00 בתיאום מראש( שי גרשטיין )שעת קבלה: רביעי ב- 18:00,

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers

More information

קורס תכנות רשימה מקושרת דוגמה: חיפוש מעבר על רשימה דוגמא: שחרור רשימה מקושרת דוגמא: הוספת אברים שלא בהתחלה

קורס תכנות רשימה מקושרת דוגמה: חיפוש מעבר על רשימה דוגמא: שחרור רשימה מקושרת דוגמא: הוספת אברים שלא בהתחלה רשימה מקושרת רשימה היא אוסף סדור של ערכים פעולות רשימה לעומת מערך קורס תכנות שיעור עשירי: מיונים, חיפושים, קצת ניתוח זמני ריצה, קצת תיקון טעויות ועוד על רשימות 3 5 7 9 typedef struct node int data; struct

More information

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

Chapter 4 Fundamental Data Types. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 4 Fundamental Data Types ICOM 4015: Advanced Programming Lecture 4 Reading: Chapter Four: Fundamental Data Types Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.

More information

More types, Methods, Conditionals. ARCS Lab.

More types, Methods, Conditionals. ARCS Lab. More types, Methods, Conditionals ARCS Lab. Division Division ( / ) operates differently on integers and on doubles! Example double a = 5.0/2.0; 0; // a = 2.5 int b = 4/2; // b = 2 int c = 5/2; // c =

More information

ת ונכת סרוק תורשוקמ תומישר :יעישת רועיש 1

ת ונכת סרוק תורשוקמ תומישר :יעישת רועיש 1 קורס תכנות שיעור תשיעי: רשימות מקושרות 1 הקצאה דינאמית של מערכים דו-ממדיים )לפחות( שלוש גישות אפשריות:.1 מערך של מערכים מצביעים לתוך מערך "גדול".2 3. מצביע יחיד למערך גדול 2 The Interface 3 (Simple) Usage

More information

מבוא למדעי המחשב תרגול 13: עצים בינאריים

מבוא למדעי המחשב תרגול 13: עצים בינאריים מבוא למדעי המחשב תרגול 13: עצים בינאריים עצים בינאריים - הגדרה הגדרה: עץ בינארי הוא עץ ריק (בלי צמתים) או עץ המורכב משורש ושני תתי-עצים, הוא עץ בינארי. ימני ושמאלי, שכל אחד מהם תרגיל 1 עץ בינארי מסודר

More information

Algorithms. Intro2CS week 5

Algorithms. Intro2CS week 5 Algorithms Intro2CS week 5 1 Computational problems A computational problem specifies an inputoutput relationship What does the input look like? What should the output be for each input? Example: Input:

More information

Programming for Engineers in Python

Programming for Engineers in Python Programming for Engineers in Python Lecture 9: Sorting, Searching and Time Complexity Analysis Autumn 2011-12 1 Lecture 8: Highlights Design a recursive algorithm by 1. Solving big instances using the

More information

Programming for Engineers in Python

Programming for Engineers in Python Programming for Engineers in Python Lecture 9: Sorting, Searching and Time Complexity Analysis Autumn 2011-12 1 Lecture 8: Highlights Design a recursive algorithm by 1. Solving big instances using the

More information

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School CSE 201 JAVA PROGRAMMING I Primitive Data Type Primitive Data Type 8-bit signed Two s complement Integer -128 ~ 127 Primitive Data Type 16-bit signed Two s complement Integer -32768 ~ 32767 Primitive Data

More information

CS110: PROGRAMMING LANGUAGE I

CS110: PROGRAMMING LANGUAGE I CS110: PROGRAMMING LANGUAGE I Computer Science Department Lecture 8: Methods Lecture Contents: 2 Introduction Program modules in java Defining Methods Calling Methods Scope of local variables Passing Parameters

More information

1.3 Conditionals and Loops. 1.3 Conditionals and Loops. Conditionals and Loops

1.3 Conditionals and Loops. 1.3 Conditionals and Loops. Conditionals and Loops 1.3 Conditionals and Loops any program you might want to write objects functions and modules graphics, sound, and image I/O arrays conditionals and loops Math primitive data types text I/O assignment statements

More information

תרגול מספר 3: מערכים

תרגול מספר 3: מערכים היום בתרגול:.1.2 תרגול מספר 3: מערכים מערך חד-מימדי: מה זה מערך ולמה צריך אותו? איך מגדירים? איך זה נראה בזכרון? דוגמאות לשימוש במערך חד-מימדי השוואה בין משתנה פרימיטיבי למשתנה שאינו פרימיטיבי מערך דו-מימדי:

More information

מבוא לתכנות ב- JAVA מעבדה 4

מבוא לתכנות ב- JAVA מעבדה 4 מבוא לתכנות ב- JAVA מעבדה 4 מה בתרגול מערכים מחרוזות מערך חד מימדי מערך הוא מבנה המחזיק סדרה של איברים מאותו טיפוס גודל המערך הוא קבוע )נקבע בעת יצירת המערך( הגישה לכל איבר היא באמצעות אינדקס למה לי מערך?

More information

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug,

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug, 1 To define methods, invoke methods, and pass arguments to a method ( 5.2-5.5). To develop reusable code that is modular, easy-toread, easy-to-debug, and easy-to-maintain. ( 5.6). To use method overloading

More information

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University Lecture 2 COMP1406/1006 (the Java course) Fall 2013 M. Jason Hinek Carleton University today s agenda a quick look back (last Thursday) assignment 0 is posted and is due this Friday at 2pm Java compiling

More information

Variables and data types

Variables and data types Survivor: CSCI 135 Variables Variables and data types Stores information your program needs Each has a unique name Each has a specific type Java built-in type what it stores example values operations String

More information

קורס תכנות שיעור שישי: מחרוזות, מצביעים

קורס תכנות שיעור שישי: מחרוזות, מצביעים קורס תכנות שיעור שישי: מחרוזות, מצביעים מערכים אוסף סדור של משתנים מאותו סוג המשתנים נמצאים ברצף בזיכרון העברת מערך לפונקציה Define רקורסיה במערך מערכים דו מימדיים 2 מחרוזות מהי מחרוזת? רצף של תוים ייצוג

More information

קורס תכנות בשיעור הקודם למדנו על רקורסיה שיעור שישי: מערכים פונקציה רקורסיבית שאלה חישוב נוסחאות רקורסיביות בשפת C

קורס תכנות בשיעור הקודם למדנו על רקורסיה שיעור שישי: מערכים פונקציה רקורסיבית שאלה חישוב נוסחאות רקורסיביות בשפת C בשיעור הקודם למדנו על רקורסיה פתרנו את בעיית מגדלי הנוי בעזרת רקורסיה כלומר בעזרת פונקציה שקוראת לעצמה. רקורסיה מאפשרת לנו לפתור בעיה "גדולה" בעזרת פתרון של בעיות "קטנות" המרכיבות אותה. קורס תכנות שיעור

More information

M e t h o d s a n d P a r a m e t e r s

M e t h o d s a n d P a r a m e t e r s M e t h o d s a n d P a r a m e t e r s Objective #1: Call methods. Methods are reusable sections of code that perform actions. Many methods come from classes that are built into the Java language. For

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 בחינה באופק! הבחינה תכלול את כל הנושאים שכיסינו במהלך הסמסטר: כל ההרצאות כל תרגולים כל תרגילי בית חומר סגור שאלות אמריקאיות 2 קצת על מנשקים מנשק יכול להרחיב שירותים במנשק הם תמיד

More information

1.3 Conditionals and Loops

1.3 Conditionals and Loops .3 Conditionals and Loops Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2008 February 04, 2008 0:00 AM A Foundation for Programming A Foundation

More information

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education AP Computer Science Return values, Math, and double Distance between points Write a method that given x and y coordinates for two points prints the distance between them If you can t do all of it, pseudocode?

More information

תוכנה 1 * לא בהכרח בסדר הזה

תוכנה 1 * לא בהכרח בסדר הזה תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים - תזכורת מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות )חתימות(. מימוש דיפולטיבי

More information

Engineering Programming A

Engineering Programming A Engineering Programming A תרגול 5 25.11.2012 מערכים חד-מימדיים )תזכורת( לדוגמא: מערך בשם Arr בגודל 8 שאיבריו מטיפוס int 3 7 5 6 8 1 23 16 0 1 2 3 4 5 6 7 ב - arr[0] ב יושב ערך שהוא המספר השלם 3 arr[1]

More information

קורס תכנות כתובות בזיכרון כתובות בזכרון מצביעים וכתובות מצביעים וכתובות שיעור שביעי: מבנים, הקצאת זיכרון דינאמית האופרטור &

קורס תכנות כתובות בזיכרון כתובות בזכרון מצביעים וכתובות מצביעים וכתובות שיעור שביעי: מבנים, הקצאת זיכרון דינאמית האופרטור & כתובות בזיכרון קורס תכנות int x = 10; char c = a ; 10 784658 'a' 26537 שם x כתובת 784658 שיעור שביעי: מבנים, הקצאת זיכרון דינאמית 26537 c 1 הגדרת מצביע variable( )pointer כתובות בזכרון האופרטור & מחזיר

More information

Java Basic Programming Constructs

Java Basic Programming Constructs Java Basic Programming Constructs /* * This is your first java program. */ class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World! ); A Closer Look at HelloWorld 2 This

More information

תוכנה 1 תרגול 2: מערכים ומבני בקרה

תוכנה 1 תרגול 2: מערכים ומבני בקרה תוכנה 1 תרגול 2: מערכים ומבני בקרה 2 Useful Eclipse Shortcuts Ctrl+1 quick fix for errors, or small refactoring suggestions Ctrl+SPACE code content assist (auto-completion) Auto completion for main create

More information

Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators

Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY Arithmetic Operators There are four basic arithmetic operations: OPERATOR USE DESCRIPTION + op1 + op2 Adds op1 and op2 - op1 + op2 Subtracts

More information

COMP 110/L Lecture 13. Kyle Dewey

COMP 110/L Lecture 13. Kyle Dewey COMP 110/L Lecture 13 Kyle Dewey Outline char, charat() Command-line arguments and arrays Array access Array length Array update Integer.parseInt char, charat() char Represents a single character char

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 בחינה באופק! הבחינה תכלול את כל הנושאים שכיסינו במהלך הסמסטר: כל ההרצאות כל תרגולים כל תרגילי בית חומר סגור שאלות אמריקאיות 2 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים

More information

MODULE 02: BASIC COMPUTATION IN JAVA

MODULE 02: BASIC COMPUTATION IN JAVA MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment

More information

הנכות 1 תואיגש םע תודדומתהו תואלול,םי : כרעמ 2 לוגרת

הנכות 1 תואיגש םע תודדומתהו תואלול,םי : כרעמ 2 לוגרת תוכנה 1 תרגול 2: מערכים, לולאות והתמודדות עם שגיאות מערכים מערכים Array: A fixed-length data structure for storing multiple values of the same type Example from last week: An array of odd numbers: Indices

More information

Calculations, Formatting and Conversions

Calculations, Formatting and Conversions Chapter 5 Calculations, Formatting and Conversions What is in This Chapter? In this chapter we discuss how to do basic math calculations as well as use some readily available Math functions in JAVA. We

More information

Lecture 6: While Loops and the Math Class

Lecture 6: While Loops and the Math Class Lecture 6: While Loops and the Math Class Building Java Programs: A Back to Basic Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. while loops 2 Categories of loops

More information

רזח יליגרתו םי יראני ב ם

רזח יליגרתו םי יראני ב ם מבוא למדעי המחשב עצים בינאריים ותרגילי חזרה תרגול 13: עצים בינאריים - הגדרה הגדרה: עץ בינארי הוא עץ ריק )בלי צמתים( או עץ המורכב משורש ושני תתי-עצים, הוא עץ בינארי. ימני ושמאלי, שכל אחד מהם שאלה עץ בינארי

More information

C programming. conditional statements

C programming. conditional statements C programming Lecture 4: Logical expressions, conditional statements Based on slides designed by Shay Artsi,Aythan Avior,Gitit Rockstein and Saher Ismir for the department of Computer Science, Technion,

More information

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington First Programs CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Output System.out.println( ) prints out something. System.out.println is the first

More information

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens Organizational Issues Inf1-OOP Course Overview Ewan Klein, Perdita Stevens School of Informatics January 12, 2013 Why Java? Hello, World! in Java Built-in Types Integers Floating-Point Numbers Type Conversion

More information

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

First Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington First Programs CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Output System.out.println( ) prints out something. System.out.println is the first

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236

More information

Java Reference Card. 1. Classes. 2. Methods. 3. Conditionals. 4. Operators

Java Reference Card. 1. Classes. 2. Methods. 3. Conditionals. 4. Operators Java Reference Card 1. Classes The following is an example of a main class: public class Calculator { public static void main(string[] args) { and the following is an example of a utility class (with no

More information

CS 61B Data Structures and Programming Methodology. June David Sun

CS 61B Data Structures and Programming Methodology. June David Sun CS 61B Data Structures and Programming Methodology June 25 2008 David Sun Announcements Visit 387 Soda to arrange for after hours access to Soda Hall. Computer Science Undergraduate Association event:

More information

Visual Programming. Lecture 2: More types, Methods, Conditionals

Visual Programming. Lecture 2: More types, Methods, Conditionals Visual Programming Lecture 2: More types, Methods, Conditionals Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Outline Lecture 1 Review More types Methods Conditionals 2 Outline Lecture 1 Review More types

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

The Math Class. Using various math class methods. Formatting the values.

The Math Class. Using various math class methods. Formatting the values. The Math Class Using various math class methods. Formatting the values. The Math class is used for mathematical operations; in our case some of its functions will be used. In order to use the Math class,

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java Organisational issues Inf1-OOP Course Overview Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics January 11, 2014 Why Java? Hello, World! in Java Built-in Types Integers Floating-Point

More information

CS 177 Spring 2010 Exam I

CS 177 Spring 2010 Exam I CS 177 Spring 2010 Exam I There are 25 multiple choice questions. Each one is worth 4 points. The total score for the exam is 100. Answer the multiple choice questions on the bubble sheet given. Fill in

More information

Review of Basic Java

Review of Basic Java Review of Basic Java 1 Background The course is a follow-on to your first programming course in Java. It is assumed you are already familiar with the basic elements of Java (such as Console, print, int,

More information